package it.gat.controller.utils;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class ImpostazioniDesktop{
	
	private static Properties properties;
	
	public static void load(InputStream inputStream)
	{
		properties = new Properties();
		try {
			properties.load(inputStream);
			initImpostazioni();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static String getProperty(String key)
	{
		return properties.getProperty(key);
	}
	
	public static void setProperty(String key,String value)
	{
		properties.setProperty(key,value);
	}

	public static void initImpostazioni() {
		WSImpostazioni.setWebserviceUrl(getProperty(WSImpostazioni.WEBSERVICEURL));
		WSImpostazioni.setWebservicePort(getProperty(WSImpostazioni.WEBSERVICEPORT));
		WSImpostazioni.setWebserviceUri(getProperty(WSImpostazioni.WEBSERVICEURI));
		
	}

	public static void saveDefault() throws IOException {
		properties = new Properties();
		properties.setProperty(WSImpostazioni.WEBSERVICEURL, "localhost");
		properties.setProperty(WSImpostazioni.WEBSERVICEPORT, "8080");
		properties.setProperty(WSImpostazioni.WEBSERVICEURI, "gat-webservice");
		FileOutputStream os = null;
		os = new FileOutputStream("config.properties");
		properties.store(os, "Impostazioni client");
		initImpostazioni();
	}
	
	public static void save() throws IOException {
		FileOutputStream os = null;
		os = new FileOutputStream("config.properties");
		properties.store(os, "Impostazioni client");
	}

}
